<!DOCTYPE html>
<html>
<!-- Created by GNU Texinfo 7.1.1, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- This file documents the use of the GNU compilers.

Copyright © 1988-2023 Free Software Foundation, Inc.

Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "Funding Free Software", the Front-Cover
Texts being (a) (see below), and with the Back-Cover Texts being (b)
(see below).  A copy of the license is included in the section entitled
"GNU Free Documentation License".

(a) The FSF's Front-Cover Text is:

A GNU Manual

(b) The FSF's Back-Cover Text is:

You have freedom to copy and modify this GNU Manual, like GNU
     software.  Copies published by the Free Software Foundation raise
     funds for GNU development. -->
<title>Function Prototypes (Using the GNU Compiler Collection (GCC))</title>

<meta name="description" content="Function Prototypes (Using the GNU Compiler Collection (GCC))">
<meta name="keywords" content="Function Prototypes (Using the GNU Compiler Collection (GCC))">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta name="viewport" content="width=device-width,initial-scale=1">

<link href="index.html" rel="start" title="Top">
<link href="Indices.html" rel="index" title="Indices">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="C-Extensions.html" rel="up" title="C Extensions">
<link href="C_002b_002b-Comments.html" rel="next" title="C++ Comments">
<link href="Attribute-Syntax.html" rel="prev" title="Attribute Syntax">
<style type="text/css">
<!--
a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
div.example {margin-left: 3.2em}
kbd.key {font-style: normal}
span.r {font-family: initial; font-weight: normal; font-style: normal}
span:hover a.copiable-link {visibility: visible}
-->
</style>


</head>

<body lang="en_US">
<div class="section-level-extent" id="Function-Prototypes">
<div class="nav-panel">
<p>
Next: <a href="C_002b_002b-Comments.html" accesskey="n" rel="next">C++ Style Comments</a>, Previous: <a href="Attribute-Syntax.html" accesskey="p" rel="prev">Attribute Syntax</a>, Up: <a href="C-Extensions.html" accesskey="u" rel="up">Extensions to the C Language Family</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Indices.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<h3 class="section" id="Prototypes-and-Old_002dStyle-Function-Definitions"><span>6.40 Prototypes and Old-Style Function Definitions<a class="copiable-link" href="#Prototypes-and-Old_002dStyle-Function-Definitions"> &para;</a></span></h3>
<a class="index-entry-id" id="index-function-prototype-declarations"></a>
<a class="index-entry-id" id="index-old_002dstyle-function-definitions"></a>
<a class="index-entry-id" id="index-promotion-of-formal-parameters"></a>

<p>GNU C extends ISO C to allow a function prototype to override a later
old-style non-prototype definition.  Consider the following example:
</p>
<div class="example smallexample">
<pre class="example-preformatted">/* <span class="r">Use prototypes unless the compiler is old-fashioned.</span>  */
#ifdef __STDC__
#define P(x) x
#else
#define P(x) ()
#endif

/* <span class="r">Prototype function declaration.</span>  */
int isroot P((uid_t));

/* <span class="r">Old-style function definition.</span>  */
int
isroot (x)   /* <span class="r">??? lossage here ???</span> */
     uid_t x;
{
  return x == 0;
}
</pre></div>

<p>Suppose the type <code class="code">uid_t</code> happens to be <code class="code">short</code>.  ISO C does
not allow this example, because subword arguments in old-style
non-prototype definitions are promoted.  Therefore in this example the
function definition&rsquo;s argument is really an <code class="code">int</code>, which does not
match the prototype argument type of <code class="code">short</code>.
</p>
<p>This restriction of ISO C makes it hard to write code that is portable
to traditional C compilers, because the programmer does not know
whether the <code class="code">uid_t</code> type is <code class="code">short</code>, <code class="code">int</code>, or
<code class="code">long</code>.  Therefore, in cases like these GNU C allows a prototype
to override a later old-style definition.  More precisely, in GNU C, a
function prototype argument type overrides the argument type specified
by a later old-style definition if the former type is the same as the
latter type before promotion.  Thus in GNU C the above example is
equivalent to the following:
</p>
<div class="example smallexample">
<pre class="example-preformatted">int isroot (uid_t);

int
isroot (uid_t x)
{
  return x == 0;
}
</pre></div>

<p>GNU C++ does not support old-style function definitions, so this
extension is irrelevant.
</p>
</div>
<hr>
<div class="nav-panel">
<p>
Next: <a href="C_002b_002b-Comments.html">C++ Style Comments</a>, Previous: <a href="Attribute-Syntax.html">Attribute Syntax</a>, Up: <a href="C-Extensions.html">Extensions to the C Language Family</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Indices.html" title="Index" rel="index">Index</a>]</p>
</div>



</body>
</html>
